package com.yc.damai.mapper;

import com.yc.damai.entity.DmPromotion;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.damai.entity.DmPromotionDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ly
 * @since 2024-09-28
 */
public interface DmPromotionMapper extends BaseMapper<DmPromotion> {

    @Select("select * from dm_promotion where status=0 order by begin limit 0,1")
    @Results(
            id = "rm1",
            value = {
                    @Result(column = "id", property = "id", id = true),
                    @Result(column = "id", property = "details",
                        many = @Many(select = "selectByPmid")),
            }
    )
    DmPromotion selectNoBegin();

    @Select("select * from dm_promotion_detail where pmid=#{pmid}")
    @Results(
            id = "rm2",
            value = {
                    @Result(column = "id", property = "id", id = true),
                    @Result(column = "pid", property = "product",
                            one = @One(select = "com.yc.damai.mapper.DmProductMapper.selectById")),
            }
    )
    List<DmPromotionDetail> selectByPmid(int pmid);

    @Select("select * from dm_promotion where id = #{id}")
    @ResultMap("rm1")
    DmPromotion queryById(int pmid);


}
